﻿CREATE TRIGGER [ArticleLikes_insert_trigger] ON [ArticleLikes] FOR INSERT AS
UPDATE [side] SET [sync_row_is_tombstone] = 0, [local_update_peer_key] = 0, [restore_timestamp] = NULL, [update_scope_local_id] = NULL, [last_change_datetime] = GETDATE(), [UserID] = [i].[UserID] FROM [ArticleLikes_tracking] [side] JOIN INSERTED AS [i] ON [side].[ArticleLikeID] = [i].[ArticleLikeID]
INSERT INTO [ArticleLikes_tracking] ([i].[ArticleLikeID], [create_scope_local_id], [local_create_peer_key], [local_create_peer_timestamp], [update_scope_local_id], [local_update_peer_key], [sync_row_is_tombstone], [last_change_datetime], [restore_timestamp], [i].[UserID]) SELECT [i].[ArticleLikeID], NULL, 0, @@DBTS+1, NULL, 0, 0, GETDATE() , NULL, [i].[UserID] FROM INSERTED AS [i] LEFT JOIN [ArticleLikes_tracking] [side] ON [side].[ArticleLikeID] = [i].[ArticleLikeID] WHERE [side].[ArticleLikeID] IS NULL